package com.detech.sbmh.base.page;

import io.swagger.annotations.ApiModelProperty;
import org.hibernate.type.Type;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

public class Page<T> implements java.io.Serializable {

	private static final long serialVersionUID = -3724690004904620605L;
	@ApiModelProperty(value="当前页")
	private String currpage; 		//当前页码
	@ApiModelProperty(value="每页记录数")
	private String eachpagecount; 	//每页显示数
	@ApiModelProperty(value="总页数")
	private String totalpage; 		//总页数
	@ApiModelProperty(value="总记录数")
	private String totalrecords; 	//总记录数
	@ApiModelProperty(value="列表主体数据")
	private List<T> bodyList; 			//列表主体数据
	@ApiModelProperty(hidden = true)
	private String hql; 			//查询列表数据的HQL语句
	@ApiModelProperty(hidden = true)
	private String sql;				//查询列表数据的sql语句
	@ApiModelProperty(hidden = true)
	private List paramList; 	//查询数据条件参数列表
	@ApiModelProperty(hidden = true)
	private List<SqlType> colChangeList;//要转成字符串的字段list
	@ApiModelProperty(value="当前排序字段")
	private String orderByColumn; 		//当前排序字段
	@ApiModelProperty(value="排序方式（升序：asc 降序：desc）")
	private String orderWise; 		//排序方式（升序：asc 降序：desc）
	@ApiModelProperty(hidden = true)
	private Class<T> returnType; 		//定义返回的实体数据类型

	public Page() {
		currpage = "1";
		eachpagecount = "20";
		totalpage = "1";
		totalrecords = "0";
		bodyList = null;
		hql = null;
		sql = null;
		paramList = null;
		colChangeList = null;
		returnType = null;
	}

	public Page(@NotNull String currpage,@NotNull String eachpagecount) {
		this.currpage = currpage;
		this.eachpagecount = eachpagecount;
	}
	
	@ApiModelProperty(hidden = true)
	public boolean isDefault(){
		if("1".equals(currpage) && "0".equals(totalrecords) && "1".equals(totalpage) && "20".equals(eachpagecount)){
			return true;
		}else{
			return false;
		}
	}

	public void addParam(Object param){
		if(paramList==null){
			paramList = new ArrayList();
		}
		paramList.add(param);
	}

	public void addColumn(String colname, Type coltype){
		if(colChangeList==null){
			colChangeList = new ArrayList<SqlType>();
		}
		SqlType colType = new SqlType();
		colType.setColname(colname);
		colType.setColtype(coltype);
		colChangeList.add(colType);
	}

	public String getCurrpage() {
		return currpage;
	}

	public void setCurrpage(String currpage) {
		this.currpage = currpage;
	}

	public String getEachpagecount() {
		return eachpagecount;
	}

	public void setEachpagecount(String eachpagecount) {
		this.eachpagecount = eachpagecount;
	}

	public String getTotalpage() {
		return totalpage;
	}

	public void setTotalpage(String totalpage) {
		this.totalpage = totalpage;
	}

	public String getTotalrecords() {
		return totalrecords;
	}

	public void setTotalrecords(String totalrecords) {
		this.totalrecords = totalrecords;
	}

	public List<T> getBodyList() {
		return bodyList;
	}

	public void setBodyList(List<T> bodyList) {
		this.bodyList = bodyList;
	}

	public String getHql() {
		return hql;
	}

	public void setHql(String hql) {
		this.hql = hql;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public List getParamList() {
		return paramList;
	}

	public void setParamList(List paramList) {
		this.paramList = paramList;
	}

	public List<SqlType> getColChangeList() {
		return colChangeList;
	}

	public void setColChangeList(List<SqlType> colChangeList) {
		this.colChangeList = colChangeList;
	}

	public Class<T> getReturnType() {
		return returnType;
	}

	public void setReturnType(Class<T> returnType) {
		this.returnType = returnType;
	}

	public String getOrderByColumn() {
		return orderByColumn;
	}

	public void setOrderByColumn(String orderByColumn) {
		this.orderByColumn = orderByColumn;
	}

	public String getOrderWise() {
		return orderWise;
	}

	public void setOrderWise(String orderWise) {
		this.orderWise = orderWise;
	}
}
